<!-- 首页 -->
<template>
  <div class="common-layout">
    <el-container>
      <el-aside width="200px">
        <el-menu active-text-color="#ffd04b" background-color="#545c64" class="el-menu-vertical-demo" default-active="2"
          text-color="#fff" router>
          <el-menu-item :index="item.auth_path" v-for="item in aclArr" v-show="item.children.length == 0">
            <el-icon><icon-menu /></el-icon>
            <span>{{ item.auth_name }}</span>
          </el-menu-item>
          <el-sub-menu :index="item.auth_path" v-for="item in aclArr" v-show="item.children.length != 0">
            <template #title>
              <el-icon>
                <location />
              </el-icon>
              <span>{{ item.auth_name }}</span>
            </template>
            <el-menu-item :index="item.auth_path" v-for="item in item.children" v-show="item.is_nav == 1">
              <el-icon><icon-menu /></el-icon>
              <span>{{ item.auth_name }}</span>
            </el-menu-item>
          </el-sub-menu>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header>
          <p>你好，{{ username }}/总裁办</p>
          <p>
            <el-button text @click="open">注销登录</el-button>
          </p>
        </el-header>
        <el-main>
          <!-- 二级路由的坑 -->
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import {
  Menu as IconMenu,
  Location,
} from '@element-plus/icons-vue'
import { ref } from 'vue'

import { useRouter } from 'vue-router'
const router = useRouter()
const aclArr = ref(JSON.parse(localStorage.getItem('acl')))
console.log(aclArr);

const username = ref(localStorage.getItem('username'))

const open = () => {
  ElMessageBox.confirm(
    '您要注销登录么？',
    'Warning',
    {
      confirmButtonText: 'OK',
      cancelButtonText: 'Cancel',
      type: 'warning',
    }
  )
    .then(() => {
      localStorage.clear()
      router.push('/login')
    })
    .catch(() => {
      console.log('不');
    })
}
</script>

<style lang="scss">
.common-layout,
.el-aside,
.el-container,
.el-menu {
  height: 100%;
}

.el-header {
  height: 80px;
  background-color: skyblue;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>